package com.tanhua.server.config;

import com.tanhua.server.interceptor.RedisCacheInterceptor;
import com.tanhua.server.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
 * @ClassName :  WebConfig
 * @Author : Tenebrous
 * @Date: 2020/12/11 15:13
 * @Description : 注册拦截器到Spring容器
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * 注入Redis缓存拦截器对象
     */
    @Autowired
    private RedisCacheInterceptor redisCacheInterceptor;

    @Autowired
    private TokenInterceptor tokenInterceptor;

    /**
     * 重写addInterceptors方法
     * @param registry          注册
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 所有的请求都会被拦截
        registry.addInterceptor(this.tokenInterceptor).addPathPatterns("/**");
        registry.addInterceptor(this.redisCacheInterceptor).addPathPatterns("/**");
    }

}